package engine.scene
{
	import engine.GameData;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import newx.StageInfo;
	import newx.com.loader.SwfLoader;
	
	public class BackSceneView extends Sprite
	{
		//场景移动时间
		private var _sceneTime			:int = 1;
		private var _sceneBitMap 		:Bitmap;
		private var _pre				:Number	=	.12;
		private var _sceneView			:SceneView;
		public function BackSceneView( sceneView : SceneView )
		{
			_sceneView = sceneView;
			
			super();
			init();
		}
		
		private function init():void
		{
			_sceneBitMap = new Bitmap();
			
			addChild(_sceneBitMap);
		}
		
		public function showScene( ):void
		{
			leave();
			
			var sceneModel : int = GameData.SceneModel;
			
			if( sceneModel  == -1 ) return;
			
			//根据场景坐标，看加载什么地图
			var bmd : BitmapData ;
			
			for( var i : int = 1; i <= 25; i++ )
			{
				SwfLoader.StartLoad( "res/scenes/" + "bscene_" + sceneModel + "_" + i + ".swf", null,onComplete,[i - 1] );
			}
			
			function onComplete( swf : MovieClip, pList : Array ):void
			{
				if(swf == null)return;
				bmd = new BitmapData(100,750);
				bmd.draw( swf );
				_sceneBitMap.bitmapData.copyPixels( bmd, bmd.rect, new Point(  ( pList[0] ) * 100 , 0 ) );
			}
			x= 0;
		}
		
		public function moveFollow(xPoint : int):void
		{
			this.x = xPoint * _pre;
		}
		
		public function move(xDistance : int, yDistance : int):void
		{
			var xPoint : int = localToGlobal( new Point(0,0)).x;
			
			if( xPoint > 0  )
			{
				this.x = 0;
			}
			if( xPoint + StageInfo.stage.stageWidth > 2500 )
			{
				this.x = 200;
			}else
			{
				this.x += xDistance * _pre;
			}
		} 
		
		public function leave():void
		{
			if( null != _sceneBitMap.bitmapData )
			{
				_sceneBitMap.bitmapData.dispose();
			}
			_sceneBitMap.bitmapData	= new BitmapData( 2500, 750, true, 0 );
		}

		public function get sceneBitMap():Bitmap
		{
			return _sceneBitMap;
		}

	}
}